package com.geoboard.dialogs;

import android.accounts.Account;
import android.app.AlertDialog;
import android.app.Dialog;
import android.content.DialogInterface;
import android.content.DialogInterface.OnClickListener;
import android.os.Bundle;
import android.support.v4.app.DialogFragment;
import android.util.Log;

import com.geoboard.ActivityInterface;


public class SelectAccountDialog extends DialogFragment{
	
	private String TAG = this.getClass().getSimpleName();
	private Account[] mAccounts;
	private ActivityInterface context;

	@Override
	public Dialog onCreateDialog(Bundle savedInstanceState) {
		Log.d(TAG, "onCreateDialog()");
		
		context = (ActivityInterface) getActivity();
		mAccounts = (Account[]) getArguments().getSerializable("android.accounts.Account");
		
		//get list of board names for the dialog
		String[] accountNames = new String[mAccounts.length];
		for (int i = 0; i < accountNames.length; i++) {
			accountNames[i] = mAccounts[i].name;
		}
		
		AlertDialog.Builder builder = new AlertDialog.Builder(getActivity());
		builder.setTitle("Select Account")
				.setItems(accountNames, createOnClickListener());
		
		return builder.create();
	}

	private OnClickListener createOnClickListener() {
		return new DialogInterface.OnClickListener() {
			
			@Override
			public void onClick(DialogInterface dialog, int which) {
				Log.d(TAG, "click registered for " + which);
			}
		};
	}
}

